package com.wolfeyes.web.controller.system;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import com.wolfeyes.framework.web.serializer.enums.SexEnum;
import com.wolfeyes.framework.web.serializer.enums.StatusEnum;
import com.wolfeyes.common.response.ResponseResult;
import com.wolfeyes.web.controller.BaseController;
//import org.anyin.gitee.cloud.lib.core.web.serializer.DictAnnotation;
import com.wolfeyes.framework.web.serializer.StringAsDictDeserializer;
import com.wolfeyes.framework.web.serializer.StringAsDictSerializer;
import com.wolfeyes.framework.web.serializer.annotation.DictAnnotation;

import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sysDict")
@Slf4j
public class SysDictController extends BaseController {

    @GetMapping("/info/{type}")
    public ResponseResult info(@PathVariable("type") String type ){
        TestDTO dto = new TestDTO();
        dto.setSex(SexEnum.MAN.getCode());
        dto.setStatus(StatusEnum.ENABLE.getCode());
        return ResponseResult.success(dto);
    }

    @PostMapping("/create")
    public ResponseResult create(@RequestBody TestForm form){
        log.info("form: {}", form);
        return ResponseResult.success(form);
    }

    @Data
    public static class TestDTO{
        @JsonSerialize(using = StringAsDictSerializer.class)
        @DictAnnotation(type = SexEnum.class)
        private String sex;

        @JsonSerialize(using = StringAsDictSerializer.class)
        @DictAnnotation(type = StatusEnum.class)
        private String status;
    }

    @Data
    public static class TestForm{
        @JsonDeserialize(using = StringAsDictDeserializer.class)
        private SexEnum sex;

        @JsonDeserialize(using = StringAsDictDeserializer.class)
        private StatusEnum status;
    }
}
